package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IArticleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.ArticleReqVO;
import com.bjc.base.bean.response.ArticleVO;

/**
 * <p>
 * 绘本推荐文章 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "article-api", tags = { "绘本推荐文章相关接口" })
public class ArticleController {

    @Autowired
    private IArticleService articleService;

	@ApiOperation("分页查询绘本推荐文章")
	@GetMapping("article/findPage")
	public ResultVO getArticlePage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			ArticleReqVO articleReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<ArticleVO> articleVOs = articleService.getList(articleReqVO);
		return ResultGenerator.getSuccess(new PageInfo<ArticleVO>(articleVOs));
	}
	
	@ApiOperation("分页查询绘本推荐文章")
	@GetMapping("article/find")
	public ResultVO getArticlee(ArticleReqVO articleReqVO) {
		ArticleVO articleVO = articleService.get(articleReqVO);
		return ResultGenerator.getSuccess(articleVO);
	}

	@ApiOperation("添加绘本推荐文章")
	@PostMapping("article/create")
	public ResultVO createArticle(@RequestBody ArticleReqVO articleReqVOs) {
		int count = articleService.insert(articleReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本推荐文章")
	@PutMapping("article/update")
	public ResultVO updateArticle(@RequestBody ArticleReqVO articleReqVOs) {
		int count = articleService.update(articleReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本推荐文章")
	@DeleteMapping("article/deleteList")
	public ResultVO deleteArticle(@ApiParam(value = "article id集合") @RequestBody int[] ids) {
		int count = articleService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
